#include "init.h"
#include "zf_common_headfile.h"
#include "ScnsInclude.h"

extern void isrAddMenu();

void init(void)
{
    clock_init(SYSTEM_CLOCK_144M);
#if defined(SCNS_YING_ENABLE)&&SCNS_YING_ENABLE==1
    uint16 errN=0;
    static const Point errPlu={0,0};
    uint64 displayUs=0;
    scnsTryInit(SCNS_STATUS_OK,scnsYingInit());
#endif
#if defined(SCNS_TIMER_ENABLE)&&SCNS_TIMER_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsTimerInit());
#endif
#if defined(SCNS_KEY_ENABLE)&&SCNS_KEY_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsKeyInit());
#endif
#if defined(SCNS_SMCTP_ENABLE)&&SCNS_SMCTP_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsSmctpInit());
#endif
#if defined(SCNS_MENU_ENABLE)&&SCNS_MENU_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsMenuInit());
    scnsMenuAddTest(9,0XFFFF);
scnsMenuLoadAll();
#endif
#if defined(SCNS_LED_ENABLE)&&SCNS_LED_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsLedInit(SCNS_LED_1));
    scnsTryInit(SCNS_STATUS_OK,scnsLedInit(SCNS_LED_2));
#endif
#if defined(SCNS_IWDG_ENABLE)&&SCNS_IWDG_ENABLE==1
    //scnsTryInit(SCNS_STATUS_OK,scnsIwdgInit());
#endif
#if defined(SCNS_POWER_ENABLE)&&SCNS_POWER_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsPowerInit());
#endif
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsLcdInit());
#endif
#if defined(SCNS_KEYBOARD_GPIO_ENABLE)&&SCNS_KEYBOARD_GPIO_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsKeyboardGpioInit());
#endif
#if defined(SCNS_BEEP_ENABLE)&&SCNS_BEEP_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsBeepInit());
#endif
#if defined(SCNS_POWER_ENABLE)&&SCNS_POWER_ENABLE==1&&defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
    scnsLcdDisplayFloat(SCNS_LCD_LAYER_AUTO,(Point){0,320-32},scnsPowerGetVoltage(),6,2,&scnsLcdFontSimSun32,SCNS_LCD_COLOR_GREEN,SCNS_LCD_COLOR_BACKGROUND,0);
#endif
#if defined(SCNS_BEEP_ENABLE)&&SCNS_BEEP_ENABLE==1
    scnsBeepAdd("1");
#endif
#if defined(SCNS_W25QXX_ENABLE)&&SCNS_W25QXX_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsW25qxxInit(SCNS_W25QXX_SPI));
    scnsTryInit(SCNS_STATUS_OK,scnsW25qxxTest(SCNS_W25QXX_SPI,0,0));
#endif
#if defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsIicInit(SCNS_IIC_CAMERA));
#endif
#if defined(SCNS_GYRO_ENABLE)&&SCNS_GYRO_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsGyroInit(SCNS_GYRO_1));
#endif
#if defined(SCNS_ZF_DM1TA_ENABLE)&&SCNS_ZF_DM1TA_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsZfDm1taInit(SCNS_ZF_DM1TA_1));
#endif
#if defined(SCNS_ZF_DM1RA_ENABLE)&&SCNS_ZF_DM1RA_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsZfDm1raInit(SCNS_ZF_DM1RA_1));
#endif
#if defined(SCNS_MT9V034_ENABLE)&&SCNS_MT9V034_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsMt9v034Init(SCNS_MT9V034_1));
#endif
#if defined(SCNS_VL53L0X_ENABLE)&&SCNS_VL53L0X_ENABLE==1
    scnsTryInit(SCNS_STATUS_OK,scnsVl53l0xInit(SCNS_VL53L0X_FRONT));
    scnsTryInit(SCNS_STATUS_OK,scnsVl53l0xInit(SCNS_VL53L0X_BACK));
#endif
#if defined(SCNS_TIMER_ENABLE)&&SCNS_TIMER_ENABLE==1
    scnsTimerMarkInited();
#endif
#if defined(SCNS_BEEP_ENABLE)&&SCNS_BEEP_ENABLE==1
    scnsBeepAdd("2");
#endif
    //isrAddMenu();
    //hxPrintfFL("Init finish %d error\n",errN);
scnsMenuLoadAll();
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
    scnsLcdDisplayInt16(SCNS_LCD_LAYER_AUTO,(Point){0,(errN)<<4},errN,&scnsLcdFontSimSun16,SCNS_LCD_COLOR_YELLOW,SCNS_LCD_COLOR_BACKGROUND,0);
#endif
#if defined(SCNS_TIMER_ENABLE)&&SCNS_TIMER_ENABLE==1&&defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
    for(;scnsTimerGetUs()<displayUs;)
    {
#if defined(SCNS_IWDG_ENABLE)&&SCNS_IWDG_ENABLE==1
        scnsIwdgFeed();
#endif
#if defined(SCNS_MENU_ENABLE)&&SCNS_MENU_ENABLE==1
        scnsMenuFresh();
#endif
    }
#endif
#if defined(SCNS_BEEP_ENABLE)&&SCNS_BEEP_ENABLE==1
    scnsBeepAdd("3");
#endif
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
    scnsLcdClear(SCNS_LCD_LAYER_AUTO,SCNS_LCD_COLOR_BACKGROUND);
#endif
#if defined(SCNS_MENU_ENABLE)&&SCNS_MENU_ENABLE==1
    scnsMenuSetMode(SCNS_MENU_MODE_KEY|SCNS_MENU_MODE_SMCTP|SCNS_MENU_MODE_LCD);
#endif
    scnsMenuAddConst(6,adc_val[0],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[1],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[2],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[3],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[4],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[5],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[6],,SCNS_TYPE_INT16);
    scnsMenuAddConst(6,adc_val[7],,SCNS_TYPE_INT16);
    interrupt_print_priority();
    dma_print();
    
}
